package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScClaTimeRule;
import com.ruoyi.system.service.IScClaTimeRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上课时间配置规则Controller
 * 
 * @author ruoyi
 * @date 2024-01-05
 */
@RestController
@RequestMapping("/system/rule")
public class ScClaTimeRuleController extends BaseController
{
    @Autowired
    private IScClaTimeRuleService scClaTimeRuleService;

    /**
     * 查询上课时间配置规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScClaTimeRule scClaTimeRule)
    {
        startPage();
        List<ScClaTimeRule> list = scClaTimeRuleService.selectScClaTimeRuleList(scClaTimeRule);
        return getDataTable(list);
    }
    /**
     * 查询某个班级排课信息
     */
//    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/ClaRulelist")
    public AjaxResult ClaRulelist(ScClaTimeRule scClaTimeRule)
    {
        List<ScClaTimeRule> list = scClaTimeRuleService.selectScClaTimeRuleList(scClaTimeRule);
        return AjaxResult.success(list);
    }

    /**
     * 导出上课时间配置规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "上课时间配置规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScClaTimeRule scClaTimeRule)
    {
        List<ScClaTimeRule> list = scClaTimeRuleService.selectScClaTimeRuleList(scClaTimeRule);
        ExcelUtil<ScClaTimeRule> util = new ExcelUtil<ScClaTimeRule>(ScClaTimeRule.class);
        util.exportExcel(response, list, "上课时间配置规则数据");
    }

    /**
     * 获取上课时间配置规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return AjaxResult.success(scClaTimeRuleService.selectScClaTimeRuleByRuleId(ruleId));
    }

    /**
     * 新增上课时间配置规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "上课时间配置规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScClaTimeRule scClaTimeRule)
    {
        return toAjax(scClaTimeRuleService.insertScClaTimeRule(scClaTimeRule));
    }

    /**
     * 修改上课时间配置规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "上课时间配置规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScClaTimeRule scClaTimeRule)
    {
        return toAjax(scClaTimeRuleService.updateScClaTimeRule(scClaTimeRule));
    }

    /**
     * 删除上课时间配置规则
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "上课时间配置规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(scClaTimeRuleService.deleteScClaTimeRuleByRuleIds(ruleIds));
    }
}
